﻿Public Class PeriodExplorer
    Inherits ExplorerTreeList

    Private aPL As PLBase

    Public Sub New(ByVal aQueryName As String)
        MyBase.New(aQueryName)
    End Sub

    Public Sub New()
        MyBase.New()
    End Sub

    Public Overrides Sub PopulateDetailSection()
        Me.Cursor = Cursors.WaitCursor
        '
        If aGridControl IsNot Nothing Then
            aGridControl.Dispose()
            aGridControl = Nothing
        End If

        Dim frmCaption As String = String.Empty
        Dim DescriptionLang As String = "_PRM"

        Dim guidEnfant As Guid = DirectCast(NodeDataRow(Me.KeyFieldName), Guid)
        Dim aMQ = MetaQuery.GetMetaQueryByName(NodeDataRow("MetaQuerie").ToString)
        aPL = PLBase.CreateInstanceOf(NodeDataRow("PL").ToString(), aMQ.QueryName)

        If Not guidEnfant.Equals(Guid.Empty) Then
            aPL.SQLWhere = String.Format("{0} = '{1}'", aMQ.GUIDField, guidEnfant)
        End If

        If AppManager.ApplicationOption.DescriptionColumnIndex = 3 Then
            DescriptionLang = "_ALT"
        Else
            DescriptionLang = "_PRM"
        End If

        If NodeDataRow.Table.Columns.Contains("Description") Then
            frmCaption = NodeDataRow("Description" & DescriptionLang)
        Else
            frmCaption = "Description" & DescriptionLang
        End If


        aGridControl = New GridExtPL() With {.Dock = DockStyle.Fill, .Pl = aPL, .SecureGrid = True, .Name = aMQ.Caption, .FormCtrlCD = MyBase.PanelName}



        '
        'On trouve la form pour effacer les controle dedans et ensuite remettre le bon.
        'Comme ca on change le Detail selon la ligne dans L'explorer
        For Each aFrm As XtraForm In Me.ParentForm.MdiChildren
            If aFrm.Name = PanelName Then
                aFrm.Controls.Clear()
                aFrm.Controls.Add(aGridControl)
                aFrm.Text = frmCaption
                aFrm.Show()
                aFrm.Focus()
            End If
            aFrm.Refresh()
        Next

        Me.Cursor = Cursors.Default
    End Sub

End Class

